package com.guigu.www.cxk.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.www.cxk.Utils.AgeUtils;
import com.guigu.www.cxk.service.CXKBespeakService;
import com.guigu.www.mapper.BespeakMapper;
import com.guigu.www.mapper.SingleDayAppointmentMapper;
import com.guigu.www.pojo.Bespeak;
import com.guigu.www.pojo.SingleDayAppointment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class CXKBespeakServiceImpl implements CXKBespeakService {
    @Autowired
    BespeakMapper bespeakMapper;

    @Autowired
    SingleDayAppointmentMapper singleDayAppointmentMapper;

    @Override
    /*添加体检人信息*/
    public int Savebespeak(Bespeak bespeak) {
        /*获取当前是时间*/
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String format = dateFormat.format(date);
        int besAge = AgeUtils.getAgeFromBrithTime(bespeak.getBesBirthday());
        bespeak.setBesAge(besAge);
        bespeak.setBesCreateTime(format);
        return bespeakMapper.insert(bespeak);
    }

    /*修改预约单预约人数信息*/
    @Override
    public int UpdateSingle(int num,String besDate) {
        return singleDayAppointmentMapper.UpdateSing(num,besDate);
    }

    @Override
    public List<Bespeak> selectbeskpeak(int sid) {
        return bespeakMapper.selectbeskpeak(sid);
    }

    @Override
    public int updateByMid(int num,String name) {
        Bespeak bespeak = new Bespeak();
        bespeak.setBesState(3);
        QueryWrapper<Bespeak> wrapper = new QueryWrapper<>();
        wrapper.eq("bes_name",name);
        return bespeakMapper.update(bespeak,wrapper);
    }

    @Override
    public int UpdateBesk(int num, String besDate) {
        return singleDayAppointmentMapper.UpdateBesk(num,besDate);
    }

    @Override
    public SingleDayAppointment selectByDate(String date) {
        QueryWrapper<SingleDayAppointment> wrapper = new QueryWrapper<>();
        wrapper.eq("sin_day_app_date",date);
        return singleDayAppointmentMapper.selectOne(wrapper);
    }
}
